<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代理商月分润统计</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
    <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
    <style>
        .edit{background-color: #ed9c3a;}
        .shenhe{background-color: #429488;}
        .see{background-color: #7cb717;}
        .cur{color:#009688;}
        .del {background-color: #e85052;}    /*.laytable-cell-1-school_icon{height:100%;}*/
        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }
        input[type="number"]{
            -moz-appearance: textfield;
        }
        .userbox,.storebox{height:190px;margin-right:0; overflow-y: auto; z-index: 999; position: absolute; left: 0px; top: 63px; width:298px; background-color:#ffffff; border: 1px solid #ddd;}
        .userbox .list,.storebox .list{height:38px;line-height: 38px;cursor:pointer; padding-left:10px;}
        .userbox .list:hover,.storebox .list:hover{background-color:#eeeeee;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-fluid">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12" style="margin-top:0px">
                        <div class="layui-card">
                            <div class="layui-card-header">代理商月分润统计</div>
                            <div class="layui-card-body">
                                <div class="layui-btn-container" style="font-size:14px;">
                                    <!-- 审核状态 -->
                                    <div class="layui-form" lay-filter="component-form-group" style="display: flex;flex-wrap: wrap;">
                                        <div class="layui-form-item">
                                            <div class="layui-inline">
                                                <div class="layui-input-inline" style="width:250px;margin-right:0;">
                                                <text class="yname">日期选择</text>
                                                <input type="text" style="border-radius:5px" class="layui-input start-item-range test-item" placeholder="日期选择" lay-key="23">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block" style="margin-left:10px;border-radius:5px">
                                                <text class="yname">门店名称</text>
                                                <input type="text" style="border-radius:5px"name="schoolname" lay-verify="schoolname" autocomplete="off" placeholder="请输入门店名称" class="layui-input inputstore">
                                                <div class="storebox" style='display: none'></div>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block" style="margin-left:10px;border-radius:5px">
                                                <text class="yname">支付方式</text>
                                                <select name="status" id="pay_type" lay-filter="pay_type">
                                                    <option value="">全部</option>
                                                    <option value="1">微信</option>
                                                    <option value="2">支付宝</option>
                                                    <option value="3">翼支付</option>
                                                    <option value="4">云闪付支付</option>
                                                    <option value="5">刷卡支付</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block" style="margin-left:10px;border-radius:5px">
                                            <text class="yname">选择通道</text>
                                                <select name="passway" id="passway" lay-filter="passway">
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block" style="margin-left:10px;border-radius:5px">
                                                <text class="yname">通道扣费模式</text>
                                                <select name="status" id="receive_model" lay-filter="receive_model">
                                                    <option value="">全部</option>
                                                    <option value="1">服务费模式</option>
                                                    <option value="2">代扣模式</option>
                                                    <option value="3">通道模式</option>
                                                    <option value="4">预充模式</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline" style="display: flex;align-items: center;margin-left: 10px;;">
                                            <button class="layui-btn layuiadmin-btn-list" lay-submit="" lay-filter="LAY-app-contlist-search" style="border-radius:5px;margin-top:-5px;margin-bottom: 0;height:36px;line-height: 36px;margin-top: 4px;">
                                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                            </button>
                                        </div>
                                        <!-- <button class="layui-btn export" style="border-radius:5px;margin-top:20px;margin-bottom: 4px;height:36px;line-height: 36px;">导出</button> -->
                                    </div>
                                </div>

                                <table class="layui-hide" id="test-table-page" lay-filter="test-table-page"></table>
                                <!-- <script type="text/html" id="statusTpl">
                                    @{{#  if(d.is_auth == 1){ }}
                                    <span>已授权</span>
                                    @{{#  } else { }}
                                    <span class="cur">未授权</span>
                                    @{{#  } }}
                                </script> -->

                                <script type="text/html" id="table-content-list">
                                    <a class="layui-btn layui-btn-xs mingxi" lay-event="mingxi" style="border-radius:3.5px;">账单明细</a>
                                    </script>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 显示明细列表 -->
<div id="openLoglist" style="display: none; background-color: #fff;">
    <div style="margin: 0 20px;">
    <!-- <button class="layui-btn logExport" style="border-radius:5px;margin-top:20px;margin-bottom: 4px;height:36px;line-height: 36px;">导出</button> -->
    <table id="openlistTable" lay-filter="openlistTable"></table>
    <script type="text/html" id="statusTemp">
    </script>
    </div>
</div>

<input type="hidden" class="store_id">
<input type="hidden" class="company_id">
<input type="hidden" class="receive_model">
<input type="hidden" class="user_id">
<input type="hidden" class="start-item">
<input type="hidden" class="end-item">
<input type="hidden" class="pay_type">
<script src="{{asset('/layuiadmin/layui/layui.js')}}"></script>
<script src="{{asset('/layuiadmin/layui/jquery-2.1.4.js')}}"></script>
<script>
    var token = localStorage.getItem("Usertoken");
    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form', 'table','laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,table = layui.table
            ,form = layui.form
            ,laydate = layui.laydate;

        // 未登录,跳转登录页面
        $(document).ready(function(){
            if(token==null){
                window.location.href="{{url('/user/login')}}";
            }
        });

        $(".inputstore").bind("input propertychange",function(event){
            var store_name = $(this).val();
            if (store_name.length == 0) {
                $('.storebox').html('');
                $('.storebox').hide();
                $('.store_id').val('')
            } else {
                $.post("{{url('/api/user/store_lists')}}",
                {
                    token:token
                    ,store_name:$(this).val()
                    ,l:100
                },function(res){
                    var html="";
                    if(res.t==0){
                        $('.storebox').html('');
                    }else{
                        for(var i=0;i<res.data.length;i++){
                            html+='<div class="list" data='+res.data[i].store_id+'>'+res.data[i].store_name+'</div>'
                        }
                        $(".storebox").show();
                        $('.storebox').html('');
                        $('.storebox').append(html);
                    }
                },"json");
            }
        });

        $(".storebox").on("click",".list",function(){
            $('.inputstore').val($(this).html());
            $('.store_id').val($(this).attr('data'));
            $('.storebox').hide();

            // table.reload('test-table-page', {
            //     where: {
            //         user_id:$('user_id').val(),
            //         store_id:$(this).attr('data')
            //     }
            //     ,page: {
            //         curr: 1
            //     }
            // });

            $("#passway").html('');

            // // 选择通道
            // $.ajax({
            //     url : "{{url('/api/user/store_open_pay_way_lists')}}",
            //     data : {
            //         token:token
            //         ,l:100
            //         ,store_id:$('.store_id').val()
            //     },
            //     type : 'post',
            //     dataType:'json',
            //     success : function(data) {
            //         var optionStr = "";
            //         for(var i=0;i<data.data.length;i++){
            //             optionStr += "<option value='" + data.data[i].company + "'>" + data.data[i].company_desc + "</option>";
            //         }
            //         $("#passway").append('<option value="">选择通道类型</option>'+optionStr);
            //         layui.form.render('select');
            //     },
            //     error : function(data) {
            //         alert('查找板块报错');

            //     }
            // });
        });

        // 选择通道
        $.ajax({
            url : "{{url('/api/user/store_open_pay_way_lists')}}",
            data : {token:token,l:100},
            type : 'post',
            dataType:'json',
            success : function(data) {
                var optionStr = "";
                for(var i=0;i<data.data.length;i++){
                    optionStr += "<option value='" + data.data[i].company + "'>"
                    + data.data[i].company_desc + "</option>";
                }
                $("#passway").append('<option value="">选择通道类型</option>'+optionStr);
                layui.form.render('select');
            },
            error : function(data) {
                alert('查找板块报错');
            }
        });

        // var pageLoading = layer.msg('数据请求中..', {
        //     icon: 16
        //     ,shade: 0.3
        //     ,time: false
        // });

        var tableIns = table.render({
            elem: '#test-table-page'
            ,url: ""
            ,method: 'get'
            ,where:{
                token:token,
            }
            ,request:{
                pageName: 'page',
                limitName: 'pagesize'
            }
            ,page: true
            ,cellMinWidth: 150
            ,cols: [[
                {field: 'month', title: '月份'}
                ,{field: 'store_id', title: '门店ID'}
                ,{field: 'store_name', title: '门店名称'}
                ,{field: 'pay_type', title: '支付类型',templet:function(info){
                    let text = ''
                    if(info.pay_type == 1){
                        text = '微信'
                    }else if(info.pay_type == 2){
                        text = '支付宝'
                    }else if(info.pay_type == 3){
                        text = '翼支付'
                    }else if(info.pay_type == 4){
                        text = '云闪付支付'
                    }else {
                        text = '刷卡支付'
                    }
                    return text
                }}
                ,{field: 'total_fee',  title: '交易金额'}
                ,{field: 'refund_fee',  title: '退款金额'}
                ,{field: 'fee_amount',  title: '手续费'}
                ,{field: 'total_num',  title: '总交易数'}
                ,{field: 'refund_num',  title: '总退款数'}
                ,{field: 'profit_column',  title: '极差分润'}
                ,{field: 'receipt_fee',  title: '实收金额'}
                ,{field: 'company_name',  title: '通道名称'}
                ,{field: 'receive_model',  title: '扣费模式',templet:function(info){
                    let text = ''
                    if(info.receive_model == 1){
                        text = '服务费模式'
                    }else if(info.receive_model == 2){
                        text = '代扣模式'
                    }else if(info.receive_model == 3){
                        text = '通道模式'
                    }else if(info.receive_model == 4){
                        text = '预充模式'
                    }
                    return text
                }}
                ,{align:'center', fixed: 'right', toolbar: '#table-content-list',title: '操作'}
            ]]
            ,response: {
                statusName: 'status' //数据状态的字段名称，默认：code
                ,statusCode: 1 //成功的状态码，默认：0
                ,msgName: 'message' //状态信息的字段名称，默认：msg
                ,countName: 'total' //数据总数的字段名称，默认：count
                ,dataName: 'data' //数据列表的字段名称，默认：data
            }
            ,done: function(res, curr, count){
//          console.log(res);
                $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
                // if(pageLoading){
                //     layer.close(pageLoading);
                // }
            }
        });

        var tableItemData = {}
        table.on('tool(test-table-page)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var e = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'mingxi'){
                tableItemData = e;
                table.render({
                    elem: '#openlistTable'
                    ,height:480
                    ,width:1250
                    ,scrollx: true // 开启水平滚动
                    ,url: "{{url('/api/v2/Commission/User/userCommissionLog')}}"
                    ,method: 'get'
                    ,where:{
                        token:token,
                        startDate:e.startDate,
                        endDate:e.endDate,
                        store_id:e.store_id,
                        company:e.company,
                        receive_model:e.receive_model,
                        pay_type:e.pay_type,
                    }
                    ,request:{
                        pageName: 'page',
                        limitName: 'pagesize'
                    }
                    ,page: true
                    ,cols: [[
                        {field: 'pay_type', title: '支付类型',width:100,templet:function(info){
                            let text = ''
                            if(info.pay_type == 1){
                                text = '微信'
                            }else if(info.pay_type == 2){
                                text = '支付宝'
                            }else if(info.pay_type == 3){
                                text = '翼支付'
                            }else if(info.pay_type == 4){
                                text = '云闪付支付'
                            }else {
                                text = '刷卡支付'
                            }
                            return text
                        }}
                        ,{field: 'store_id',  title: '门店ID',width:200}
                        ,{field: 'store_name',  title: '门店名称',width:200}
                        ,{field: 'total_fee',  title: '交易金额',width:100}
                        ,{field: 'refund_fee',  title: '退款金额',width:100}
                        ,{field: 'fee_amount',  title: '手续费',width:100}
                        ,{field: 'profit_column',  title: '极差分润',width:100}
                        ,{field: 'receipt_fee',  title: '实收金额',width:100}
                        ,{field: 'company_name',  title: '通道名称',width:100}
                        ,{field: 'receive_model',  title: '扣费模式',width:100,templet:function(info){
                            let text = ''
                            if(info.receive_model == 1){
                                text = '服务费模式'
                            }else if(info.receive_model == 2){
                                text = '代扣模式'
                            }else if(info.receive_model == 3){
                                text = '通道模式'
                            }else if(info.receive_model == 4){
                                text = '预充模式'
                            }
                            return text
                        }}
                    ]]
                    ,response: {
                        statusName: 'status' //数据状态的字段名称，默认：code
                        ,statusCode: 1 //成功的状态码，默认：0
                        ,msgName: 'message' //状态信息的字段名称，默认：msg
                        ,countName: 'total' //数据总数的字段名称，默认：count
                        ,dataName: 'data' //数据列表的字段名称，默认：data
                    }
                    ,done: function(res, curr, count){
                        $('th').css({'font-weight': 'bold', 'font-size': '15','color': 'black','background':'linear-gradient(#f2f2f2,#cfcfcf)'});	//进行表头样式设置
                    }
                });
                layer.open({
                    type: 1,
                    title: '按月分润明细列表',
                    closeBtn: 1,
                    area: '1250px',
                    shadeClose: true,
                    content: $('#openLoglist'),
                    success: function(layero, index) {
                    }
                });
            }
            });

        laydate.render({
            elem: '.start-item-range'
            ,type: 'date'
            ,range:'至'
            ,max: 0 // 限制最大日期为今天
            ,done: function(value){
                if(value){
                    $('.start-item').val(value.substring(0,10))
                    $('.end-item').val(value.substring(13,value.length))
                }else{
                    $('.start-item').val('')
                    $('.end-item').val('')
                }
            }
        });

        // 监听输入框的变化，如果为空则清空另一个输入框的值
        $('#start-item-range').on('input', function() {
            if ($(this).val() === '') {
                $('.start-item').val('')
                $('.end-item').val('')
            }
        });

        // 选择通道类型
        form.on('select(passway)', function(data){
            var company_id = data.value;
            $('.company_id').val(company_id);

            //执行重载
            // table.reload('test-table-page', {
            //     where: {
            //         company:company_id
            //     }
            //     ,page: {
            //         curr: 1 //重新从第 1 页开始
            //     }
            // });
        });

         // 选择通道扣费模式
         form.on('select(receive_model)', function(data){
            var model = data.value;
            $('.receive_model').val(model);

            //执行重载
            // table.reload('test-table-page', {
            //     where: {
            //         company:company_id
            //     }
            //     ,page: {
            //         curr: 1 //重新从第 1 页开始
            //     }
            // });
        });

         // 选择支付方式
         form.on('select(pay_type)', function(data){
            var model = data.value;
            $('.pay_type').val(model);

            //执行重载
            // table.reload('test-table-page', {
            //     where: {
            //         company:company_id
            //     }
            //     ,page: {
            //         curr: 1 //重新从第 1 页开始
            //     }
            // });
        });

         //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            //执行重载
            var pageLoading = layer.msg('数据请求中..', {
                icon: 16
                ,shade: 0.3
                ,time: false
            });
            let starttime = $('.start-item').val();
            let endtime = $('.end-item').val();
            let startDate = '';
            let endDate = '';
            if(starttime && endtime){
                //处理开始时间和结束时间
                startDate = starttime.length<12 ? starttime + ' 00:00:00' : starttime;
                endDate = endtime.length<12 ? endtime + ' 23:59:59' : endtime;
            }else{
                layer.msg('请选择时间!') 
                return
            }
            let Values = { 
                startDate:startDate,
                endDate:endDate,
                pay_type:$('.pay_type').val(),
                company:$('.company_id').val(),
                store_id:$('.store_id').val(),
                receive_model:$('.receive_model').val(),
                token:token,
            }
            // let paramsValue = {
            //     token:token
            // }
            // for(let i in Values){
            //   if(Values[i]){
            //     paramsValue[i] = Values[i]
            //   }
            // }
            tableIns.reload({
                url: "{{url('/api/v2/Commission/User/userCommission')}}",
                where: Values,
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                done:function(res, curr, count){
                    layer.close(pageLoading);
                }
            });
        });
        
    });

</script>

</body>
</html>
